﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Farigola.Engine.SystemData.DataValue;

namespace Farigola.Engine.Factories
{
    /// <summary>
    /// The factory to build DataValue.
    /// </summary>
    public class FactoryDataValue
    {
        private FactoryCommon _factoryCommon;

         //=====================================================================
        #region Constructors.

        //---------------------------------------------------------------------
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="factoryCommon"></param>
        public FactoryDataValue(FactoryCommon factoryCommon)
        {
            _factoryCommon = factoryCommon;
        }

        #endregion

        //=====================================================================
        #region get/set methods.

        //---------------------------------------------------------------------
        /// <summary>
        /// get the type of data value, by th name.
        /// </summary>
        /// <param name="typeItemName"></param>
        /// <returns></returns>
        public bool GetDataValueTypeByName(string typeItemName, out DataValueType dataValueType)
        {
            dataValueType = DataValueType.Undefined;

            if (typeItemName == null)
                return false;

            typeItemName = typeItemName.Trim();
            if (typeItemName.Length == 0)
                return false;

            if (typeItemName.Equals(DataValueType.String.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                dataValueType = DataValueType.String;
                return true;
            }

            if (typeItemName.Equals(DataValueType.Int.ToString(), StringComparison.OrdinalIgnoreCase))
            {
                dataValueType = DataValueType.Int;
                return true;
            }

            return false;
        }

        #endregion

        //=====================================================================
        #region Create methods.

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a data value.
        /// </summary>
        /// <returns></returns>
        public DataValueString CreateDataValueString()
        {
            return new DataValueString();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a data value, with an int value.
        /// </summary>
        /// <returns></returns>
        public DataValueString CreateDataValueString(string value)
        {
            // the value can be null???
            // todo:

            return new DataValueString(value);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a data value.
        /// </summary>
        /// <returns></returns>
        public DataValueInt CreateDataValueInt()
        {
            return new DataValueInt();
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// Create a data value, with an int value.
        /// </summary>
        /// <returns></returns>
        public DataValueInt CreateDataValueInt(int value)
        {
            // the value can be null???
            // todo:

            return new DataValueInt(value);
        }

        //---------------------------------------------------------------------
        public DataValueBase CreateDataValue(DataValueType dataValueType)
        {
            if (dataValueType == DataValueType.String)
                return CreateDataValueString();

            if (dataValueType == DataValueType.Int)
                return CreateDataValueInt();

            // err, type not defined
            return null;
        }
        #endregion
    }
}
